export default {
  namespaced: true,

  state: () => ({
    wthr: JSON.parse(localStorage.getItem('wthr')) || '{}',

    futureWthr: JSON.parse(localStorage.getItem('futureWthr' || '[]')),

    lastUpTime: JSON.parse(localStorage.getItem('lastUpTime')) || '0',

    citiesList: JSON.parse(localStorage.getItem('citiesList')) || [],
  }),
  mutations: {
    updateWthr(state, value) {
      state.wthr = value

      this.commit('m_wthr/saveTdWthr')
    },
    saveTdWthr(state) {
      localStorage.setItem('wthr', JSON.stringify(state.wthr))
    },
    updateFutureWthr(state, value) {
      state.futureWthr = value
      this.commit('m_wthr/saveFutureWthr')
    },
    saveFutureWthr(state) {
      localStorage.setItem('futureWthr', JSON.stringify(state.futureWthr))
    },
    updateTime(state, time) {
      state.lastUpTime = time
      this.commit('m_wthr/saveTime')
    },
    saveTime(state) {
      localStorage.setItem('lastUpTime', JSON.stringify(state.lastUpTime))
    },
    updateCitiesList(state, newCities) {
      state.citiesList = newCities
      this.commit('m_wthr/saveCitiesList')
    },
    saveCitiesList(state) {
      localStorage.setItem('citiesList', JSON.stringify(state.citiesList))
    },
  },
}
